package com.question;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class QuestionHM1 {

    public  static  void  main(String []args)
    {
        final BlockingQueue queue=new ArrayBlockingQueue(5);

        for (int j=0;j<5;j++)
        {
            new Thread(new Runnable() {
                public void run() {
                    while (true)
                    {
                        try {
                            String data= (String) queue.take();
                            process(data);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }

                }
            }).start();
        }

         for(int i=0;i<25;i++)
         {
             String data=i+"";
             try {

                     queue.put(data);

             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
             //process(data);
         }



    }
    static void  process(String data)
    {
        try {
            System.out.println(Thread.currentThread().getName()+"处理数据——"+ data+"——在时间"+System.currentTimeMillis());
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
